<script type="text/javascript">
	$(document).ready(function() {
		$("#tabs").tabs();
		
		$("#selections-1").tablesorter({
			widthFixed: true,
			widgets: ['zebra']
		}).tablesorterPager({
			container: $("#pager1")
		});

		$("#selections-2").tablesorter({
			widthFixed: true,
			widgets: ['zebra']
		}).tablesorterPager({
			container: $("#pager2")
		});

		$("#selections-3").tablesorter({
			widthFixed: true,
			widgets: ['zebra']
		}).tablesorterPager({
			container: $("#pager3")
		});

		$("#selections-4").tablesorter({
			widthFixed: true,
			widgets: ['zebra']
		}).tablesorterPager({
			container: $("#pager4")
		});

		$("#selections-5").tablesorter({
			widthFixed: true,
			widgets: ['zebra']
		}).tablesorterPager({
			container: $("#pager5")
		});
	});

	jQuery(document).ajaxStart(function() {
		var progress = noty({
			id: "progress",
			text: $(document.createElement('div')).append(
					$(document.createElement('img')).attr({
						width : "12",
						height : "12",
						alt: "",
						src: "<?php echo base_url().'theme/default/images/loading.gif'; ?>"
					}),
					$(document.createElement('span')).text("  memproses request...")
				),
			type: "alert",
			layout: "top",
			theme: "default",
			timeout: 5000,
			animation: {
				open: {height: 'toggle'},
			    close: {height: 'toggle'},
			    easing: 'swing',
				speed: 200
			}
		});
	});
	
	jQuery(document).ajaxStop(function() {
		$.noty.close("progress");
	});

	function gotoverification() {
		var n = noty({
			text: "Tolak verifikasi semua mahasiswa yang berstatus mendaftar di beasiswa ini?",
			type: "warning",
			dismissQueue: true,
			layout: "center",
			theme: "default",
			buttons: [
				{addClass: 'btn btn-primary', text: 'Ok', onClick: function($noty) {
			        $noty.close(); 
			        request_verification(); }
				},
			    {addClass: 'btn btn-danger', text: 'Cancel', onClick: function($noty) {
			    	$noty.close(); }
			    }
			]
		});
	}

	function request_verification() {
		var id = "<?php echo $scholarship->id; ?>";
		var token = $("input[name=smb_36742cef0aed]").val();
		$.ajax({
			type: "POST",
			url: "<?php echo site_url($role.'/scholar/selection/saveverification'); ?>",
			data: { id : id, 'smb_36742cef0aed' : token },
			dataType: "json",
			success: function (data) {
				var n = noty({
					text: data.message,
					type: data.type,
					dismissQueue: true,
					layout: 'center',
					theme: 'default',
					timeout: 1000,
					animation: {
						open: {height: 'toggle'},
					    close: {height: 'toggle'},
					    easing: 'swing',
						speed: 200
					}
				});
				if (data.status == "success") {
					$(".selectionstatus").filter(function() {
					    return $(this).text() == "mendaftar";
					}).text("tidak terverifikasi");
				}
			},
			error: function (jqXHR, textStatus, errorThrown) {
				var n = noty({
					text: errorThrown,
					type: "error",
					dismissQueue: true,
					layout: 'center',
					theme: 'default',
					timeout: 1000,
					animation: {
						open: {height: 'toggle'},
					    close: {height: 'toggle'},
					    easing: 'swing',
						speed: 200
					}
				});
			}
		});
	}
	
<?php if ($role == 'adkesma') : ?>
	function gotorecomendationpage() {
		var url = "<?php echo site_url($role.'/scholar/selection/recomend/'.$scholarship->id); ?>";
		document.location.href = url; 
	}
<?php elseif ($role == 'mahalum') : ?>
	function gotoselectionpage() {
		var url = "<?php echo site_url($role.'/scholar/selection/approve/'.$scholarship->id); ?>";
		document.location.href = url;
	}

	function gotorejection() {
		var n = noty({
			text: "Tolak semua mahasiswa yang berstatus terverifikasi/direkomendasikan di beasiswa ini?",
			type: "warning",
			dismissQueue: true,
			layout: "center",
			theme: "default",
			buttons: [
				{addClass: 'btn btn-primary', text: 'Ok', onClick: function($noty) {
			        $noty.close(); 
			        request_rejection(); }
				},
			    {addClass: 'btn btn-danger', text: 'Cancel', onClick: function($noty) {
			    	$noty.close(); }
			    }
			]
		});
	}

	function request_rejection() {
		var id = "<?php echo $scholarship->id; ?>";
		var token = $("input[name=smb_36742cef0aed]").val();
		$.ajax({
			type: "POST",
			url: "<?php echo site_url($role.'/scholar/selection/saverejection'); ?>",
			data: { id : id, 'smb_36742cef0aed' : token },
			dataType: "json",
			success: function (data) {
				var n = noty({
					text: data.message,
					type: data.type,
					dismissQueue: true,
					layout: 'center',
					theme: 'default',
					timeout: 1000,
					animation: {
						open: {height: 'toggle'},
					    close: {height: 'toggle'},
					    easing: 'swing',
						speed: 200
					}
				});
				if (data.status == "success") {
					$(".selectionstatus").filter(function() {
					    return $(this).text() == "direkomendasikan" 
						    || $(this).text() == "mendaftar";
					}).text("ditolak");
					var register = parseInt($("#registercounter").text());
					var accept = parseInt($("#acceptcounter").text());
					var reject = parseInt($("#rejectcounter").text());
					reject = register - accept;
					$("#rejectcounter").text(reject); 
					document.location.reload();
				}
			},
			error: function (jqXHR, textStatus, errorThrown) {
				var n = noty({
					text: errorThrown,
					type: "error",
					dismissQueue: true,
					layout: 'center',
					theme: 'default',
					timeout: 1000,
					animation: {
						open: {height: 'toggle'},
					    close: {height: 'toggle'},
					    easing: 'swing',
						speed: 200
					}
				});
				window.location.reload();
			}
		});
	}
<?php endif; ?>
</script>

<?php 
	function verify_filter($student) {
		if ($student->status == 'terverifikasi') {
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	function register_filter($student) {
		if ($student->status == 'mendaftar' || $student->status == 'tidak terverifikasi') {
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	function recomend_filter($student) {
		if ($student->status == 'direkomendasikan') {
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	function reject_filter($student) {
		if ($student->status == 'ditolak') {
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	function approve_filter($student) {
		if ($student->status == 'aktif') {
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	$categories = array(
		1 => array_filter($recievers, "register_filter"),
		2 => array_filter($recievers, "verify_filter"),
		3 => array_filter($recievers, "recomend_filter"),
		4 => array_filter($recievers, "approve_filter"),
		5 => array_filter($recievers, "reject_filter")
	);
?>
<div id="main-content" class="prepend-1 span-19 last">
	<h3>Detil Beasiswa - <?php echo $scholarship->name; ?></h3>
	<table>
		<tr>
			<td width="250"><label>Nama Beasiswa</label></td>
			<td><?php echo $scholarship->name; ?></td>
		</tr>
		<tr>
			<td><label>Awal Periode</label></td>
			<td><?php echo date(MONTH_YEAR_FORMAT, strtotime($scholarship->period_start)); ?></td>
		</tr>
		<tr>
			<td><label>Akhir Periode</label></td>
			<td><?php echo date(MONTH_YEAR_FORMAT, strtotime($scholarship->period_end)); ?></td>
		</tr>
		<tr>
			<td><label>Batas Pendaftaran</label></td>
			<td><?php echo date(DAY_FORMAT, strtotime($scholarship->deadline)); ?></td>
		</tr>
		<tr>
			<td><label>Jenis Beasiswa</label></td>
			<td><?php echo $scholarship->type.nbs(3); ?></td>
		</tr>
		<tr>
			<td><label>Sponsor</label></td>
			<td><?php echo $scholarship->sponsor; ?></td>
		</tr>
		<tr>
			<td><label>Berkas Dibutuhkan</label></td>
			<td><?php echo $scholarship->required_files; ?></td>
		</tr>
		<tr>
			<td><label>Keterangan</label></td>
			<td><?php echo $scholarship->details; ?></td>
		</tr>
		<tr>
			<td><label>Status</label></td>
			<td><span class="info"><?php echo $status; ?></span></td>
		</tr><!-- 
		<tr>
			<td><b>Jumlah Pendaftar</b></td>
			<td id="registercounter"><?php echo count($recievers)?></td>
		</tr>
		<tr>
			<td><b>Jumlah Pendaftar Terverifikasi</b></td>
			<td><?php echo count($categories[2]); ?>
		</tr>
		<tr>
			<td><b>Jumlah Pendaftar Direkomendasikan</b></td>
			<td><?php echo count($categories[3]); ?></td>
		</tr>
		<tr>
			<td><b>Jumlah Pendaftar Diterima</b></td>
			<td id="acceptcounter"><?php echo $counter['diterima']; ?></td>
		</tr>
		<tr>
			<td><b>Jumlah Pendaftar Ditolak</b></td>
			<td id="rejectcounter"><?php echo $counter['ditolak']; ?></td>
		</tr> -->
	</table>
	<div class="clear"><?php echo nbs(); ?></div>
<?php if ($role == 'mahalum') : ?>
	<h4>Seleksi Penerimaan Beasiswa</h4>
	<p>
		Klik tombol Proses Penerimaan untuk menyeleksi mahasiswa yang diterima di beasiswa ini. Hanya mahasiswa dengan status terverifikasi atau direkomendasikan dapat diterima.
		Mahasiswa dengan status mendaftar tidak dapat diproses penerimaannya pada beasiswa ini.<br />
		Klik tombol Proses Penolakan untuk menolak semua mahasiswa di beasiswa ini. Mahasiswa yang diterima akan tetap berstatus diterima.
		Mahasiswa dengan status terverifikasi dan direkomendasikan akan diproses penolakannya. <br />
		Klik tombol Proses Penolakan Verifikasi untuk mengubah mahasiswa dengan status mendaftar menjadi tidak terverfikasi.
	</p>
	<br />
<?php echo form_open(); ?>	
	<input type="button" class="submit" name="selection" value="Proses Penerimaan" onclick="gotoselectionpage()" />
	<input type="button" class="submit" name="selection" value="Proses Penolakan" onclick="gotorejection()" />
	<input type="button" class="submit" name="selection" value="Proses Penolakan Verifikasi" onclick="gotoverification()" />
<?php echo form_close(); ?>
<?php elseif ($role == 'adkesma') : ?>
	<h4>Rekomendasi Penerimaan Beasiswa</h4>
	<p>
		Klik tombol Proses Rekomendasi untuk merekomendasikan pendaftar beasiswa terverifikasi ke mahalum.<br />
		Klik tombol Proses Penolakan Verifikasi untuk mengubah mahasiswa dengan status mendaftar menjadi tidak terverfikasi.
	</p>
	<br />
<?php echo form_open(); ?>
	<input type="button" class="submit" name="selection" value="Proses Rekomendasi" onclick="gotorecomendationpage()" />
	<input type="button" class="submit" name="selection" value="Proses Penolakan Verifikasi" onclick="gotoverification()" />
<?php echo form_close(); ?>
<?php endif; ?>
	<div class="clear"><?php echo nbs(); ?></div>
	<h4><?php echo $title; ?></h4>
<div id="tabs">
	<ul>
		<li><a href="#tabs-1">Pendaftar Beasiswa</a></li>
		<li><a href="#tabs-2">Pendaftar Terverifikasi</a></li>
		<li><a href="#tabs-3">Pendaftar Direkomendasikan</a></li>
		<li><a href="#tabs-4">Pendaftar Diterima</a></li>
		<li><a href="#tabs-5">Pendaftar Ditolak</a></li>
	</ul>
<?php 
	foreach ($categories as $key => $category) :
?>
	<div id="tabs-<?php echo $key; ?>">
	<table id="selections-<?php echo $key; ?>">
	<thead>
		<tr>
			<th>Nama Mahasiswa</th>
			<th width="150">Angkatan</th>
			<th width="300">Program Studi</th>
			<th width="200"><?php echo $studentstatus; ?></th>
		</tr>
	</thead>
	<tfoot>
		<?php echo $pager[$key]; ?>
	</tfoot>
	<tbody>
<?php 
	if ($category == NULL) :
?>
		<tr>
			<td align="center" colspan="4">
				<span class="info"><?php echo $empty; ?></span>
			</td>
		</tr>
<?php 
	else :
		foreach ($category as $reciever) :
?>
		<tr>
			<td><?php echo anchor($role.'/student/profile/index?id='.$reciever->id, $reciever->name, array('target' => '_blank')); ?></td>
			<td align="center"><?php echo $reciever->year; ?></td>
			<td><?php echo $reciever->major; ?></td>
<?php if ($type == SELEKSI && ($reciever->status == 'aktif' || $reciever->status == 'non-aktif')) :?>
			<td align="center" class="selectionstatus"><?php echo 'diterima'; ?></td>
<?php 
	else : 
?>
			<td align="center" class="selectionstatus"><?php echo $reciever->status; ?></td>
<?php 
	endif;
?>
		</tr>
<?php 
		endforeach;
	endif;
?>
	</tbody>
	</table>
	</div>
<?php endforeach; ?>
</div>
<div class="clear"><?php echo nbs(); ?></div>
</div>